package com.hdax.dm.item.service.impl;

import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import com.hdax.dm.entity.item.Cinema;
import com.hdax.dm.entity.item.Item;
import com.hdax.dm.item.dto.CommodityDto;
import com.hdax.dm.item.feign.ImageFeign;
import com.hdax.dm.item.mappers.ItemMapper;
import com.hdax.dm.item.service.CinemaService;
import com.hdax.dm.item.service.ItemService;
import org.springframework.beans.BeanUtils;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

@Service
public class ItemServiceImpl extends ServiceImpl<ItemMapper, Item> implements ItemService {

    @Autowired
    private CinemaService cinemaService;
    @Autowired
    private ImageFeign imageFeign;


    @Override
    public CommodityDto selectId(Long id) {
        CommodityDto itemDetailDto = new CommodityDto();
        //根据Id插叙对应的商品信息
        Item item = getById(id);
        //根据商品Id查询相对应的剧场信息
        Cinema cinema = cinemaService.getById(item.getCinemaId());
        //查询到的商品信息以及剧场信息中字段跟itemDetailDto中字段相同的进行数据映射
        BeanUtils.copyProperties(cinema,itemDetailDto);
        BeanUtils.copyProperties(item,itemDetailDto);
        itemDetailDto.setStartTime(item.getStartTime());
        itemDetailDto.setEndTime(item.getEndTime());
        itemDetailDto.setLatitude(cinema.getLatitude());
        itemDetailDto.setLatitude(cinema.getLatitude());
        //远程调用base微服务中的image表中的方法 根据商品id等条件查询商品图片
        itemDetailDto.setImgUrl(imageFeign.image(item.getId(),2L,1L)==null?"":imageFeign.image(item.getId(),2L,1L).getImgUrl());
        return itemDetailDto;
    }
}
